
#include "agentInitBigTree.h"

node* agentInitBigTree::splitRecs(bitset<TRAIN_RECORD_COUNT>* records)
{
    node* tmpNode = determineSplit(records);

    if (tmpNode != NULL)
    {
        bitset<TRAIN_RECORD_COUNT>* gtRecords = new bitset<TRAIN_RECORD_COUNT>;
        gtRecords->reset();

        // Figure out which records would be handled by which child
        for (int i = 0; i < TRAIN_RECORD_COUNT; i++)
        {
             if ((*records)[i])
             {
                 if (!tmpNode->evaluatesLeft(thePool->getTrainingSet()->getNthRecord(i)))
                 {
                     records->reset(i);
                     gtRecords->set(i);
                 }
             }
        }
        node* leaf = splitRecs(gtRecords);
        tmpNode->setRight(leaf);
        delete gtRecords;

        leaf = splitRecs(records);
        tmpNode->setLeft(leaf);
    }
    return tmpNode;
}

void agentInitBigTree::run()
{
    solution* tmpSolution = new solution();

    bitset<TRAIN_RECORD_COUNT> records;
    records.set();

    node* tmpNode = splitRecs(&records);

    if (tmpNode != NULL)
    {
        tmpSolution->setRoot(tmpNode);

        insert(tmpSolution);
    }

}
